package com.fg.estate.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 丰哥
 * 2022/10/17
 *
 * 登录认证拦截器
 */
public class AdminInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println("进入拦截器了.....");
        Object admin = request.getSession().getAttribute("admin");
        if (admin == null) {
            // 重定向到登录画面
            response.sendRedirect(request.getContextPath() + "/loginUi");
            // 拦截
            return false;
        }

        // 放行
        return true;
    }
}
